#coding=utf-8
from django.db import models
from datetime import datetime
        
class PatientInfo(models.Model):
    sort = models.CharField('来自', choices=(('I', '门诊'),('O', '住院')),
                              maxlength=1)
    num = models.CharField('编号', maxlength=30, blank=True)
    pid = models.CharField('影像编号', maxlength=30, unique=True,
                           default=datetime.now().strftime('%y%m%d%H%M%S'))
    name = models.CharField('姓名', maxlength=30)
    pname = models.CharField('拼音', maxlength=30)
    gender = models.CharField('性别', choices=(('M', '男'),('F', '女')),
                              maxlength=1, radio_admin=True)
    age = models.CharField('年龄', maxlength=4)
    weight = models.IntegerField('体重', maxlength=4)
    summary = models.CharField('描述', maxlength=30)
    address = models.CharField('地址/单位', maxlength=200, blank=True)
    isrx = models.BooleanField('预备', default=False)
    isrp = models.BooleanField('报告', default=False)
    re_date = models.DateTimeField('登记时间', default=datetime.now())
    rp_date = models.DateTimeField('报告时间', default=datetime.now(), blank=True)

    def __str__(self):
        return self.name
    
    class Meta:
        ordering = ('re_date',)
        
    class Admin:
        list_display = ('pid', 'name', 'age', 'gender', 'isrx', 'isrp', 're_date',)
        list_filter = ['re_date']
        search_fields = ['num', 'pid', 'name', 'pname',]
        date_hierarchy = 're_date'
    
